import time

from selenium.webdriver.common.by import By
import pytest,os,allure
from Base import Base
import logging
from util import get_logger
logger = get_logger(__name__)
class Page(Base):
     # 断言1：账号登录
    dy1_text = (By.XPATH, '/html/body/div[3]/div[3]/div[1]/div/div[3]/h2')
     # 进入frame框架
    goto_frame_loc = (By.XPATH, '/html/body/div[3]/div[3]/div[1]/div/div[3]/div[1]/div[2]/iframe')
     # 输入用户名
    input_username = (By.XPATH, '/html/body/div[2]/div[2]/div[2]/form/div/div[1]/div[2]/input')
     # 输入密码
    input_password = (By.XPATH, '/html/body/div[2]/div[2]/div[2]/form/div/div[3]/div[2]/input[2]')
     # 点击登录
    click_login = (By.XPATH, '//*[@id="dologin"]')
     # 断言2 ；账号198****5897@163.com
    dy2_text = (By.ID, 'spnUid')
     # 点击写信
    click_email_loc = (By.XPATH, '/html/body/div[1]/nav/div[1]/ul/li[2]')
     # 输入收件人
    input_people_loc = (By.XPATH, '/html/body/div[2]/div[1]/div[2]/div[1]/section/header/div[1]/div[1]/div/div[2]/div/input')
     # 输入主题
    input_object_loc = (By.XPATH, '/html/body/div[2]/div[1]/div[2]/div[1]/section/header/div[2]/div[1]/div/div/input')
     # 进入frame框架
    second_frame_loc = (By.XPATH, '/html/body/div[2]/div[1]/div[2]/div[1]/section/section/div/div[1]/div[1]/div[2]/iframe')
     # 输入邮件信息
    input_message_loc = (By.XPATH, '/html/body')
     # 点击发送
    send_email_loc = (By.XPATH, '/html/body/div[2]/div[1]/div[2]/div[1]/section/footer/div[1]')
     # 断言3 邮件发送成功
    dy3_text = (By.XPATH, '/html/body/div[2]/div[1]/div[2]/div[2]/section/h1')
    def dy1(self):
        return self.text(self.dy1_text)

    def goto_frame(self):
        self.frame(self.goto_frame_loc)

    @allure.step('用户名输入')
    def username(self):
        self.send_keys(self.input_username,'18986670716')

    @allure.step('密码输入')
    def password(self):
        self.send_keys(self.input_password,'ZXR2004zxr')
    @allure.step('点击登录')
    def login(self):
        self.click(self.click_login)
        #退出frame框架
        self.frame_quit()

    def dy2(self):
        return self.text(self.dy2_text)
    @allure.step('点击写信')
    def click_email(self):
        self.click(self.click_email_loc)


    @allure.step('输入收件人')
    def input_people(self):
        self.send_keys(self.input_people_loc,'1441688225@qq.com')


    @allure.step('输入主题')
    def input_object(self):
        self.send_keys(self.input_object_loc,'一份邮件')

    def second_frame(self):
        self.frame(self.second_frame_loc)

    @allure.step('输入邮件信息')
    def unput_message(self):
        self.send_keys(self.input_message_loc,'这是邮件的内容，我正在输入内容')
        #退出frame框架
        self.frame_quit()

    def send_email(self):
        self.click(self.send_email_loc)

    def dy3(self):
        return self.text(self.dy3_text)


    def luoji(self):
        self.open_url('https://mail.163.com/')

        logger.info('断言登录')
        with allure.step('断言登录'):
            assert '账号登录' == self.dy1()
        logger.info(f'断言登录：{self.dy1()}')

        print(self.dy1())
        self.goto_frame()
        self.username()
        self.password()
        self.login()

        logger.info('断言登陆成功')
        assert '189****0716@163.com' in self.dy2()
        print(self.dy2())
        logger.info(f'断言登陆成功：{self.dy2()}')

        self.click_email()
        self.input_people()
        self.input_object()
        self.second_frame()
        self.unput_message()
        self.send_email()

        logger.info('邮件发送成功')
        assert '邮件发送成功' in self.dy3()
        print(self.dy3())
        logger.info(f'断言邮件发送成功：{self.dy3()}')




